def get_current_memory_gb() -> int:
    import os
    import psutil
    # 获取当前进程内存占用。
    pid = os.getpid()
    p = psutil.Process(pid)
    info = p.memory_full_info()
    return info.uss / 1024. / 1024. / 1024.
def monitor(max=1,times=0.5):
    import gc
    import time
    while True:
        time.sleep(times)
        if get_current_memory_gb() > max:
            gc.collect()
def start():
    import threading
    thread = threading.Thread(target=monitor)
    thread.start()